package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.content.mapper.CourseBaseMapper;
import com.xuecheng.content.model.PageParams;
import com.xuecheng.content.model.PageResult;
import com.xuecheng.content.model.dto.QueryCourseParamsDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.service.CourseBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 课程基本信息 服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class CourseBaseServiceImpl extends ServiceImpl<CourseBaseMapper, CourseBase> implements CourseBaseService {

    /**
     * @param pageParams        分页参数
     * @param queryCourseParams 条件
     * @return com.xuecheng.content.model.PageResult<com.xuecheng.content.model.po.CourseBase>
     * @description 课程查询接口
     * @author 31115
     * @date 2022/12/24 14:13
     */
    @Override
    public PageResult<CourseBase> queryCourseBaseList(PageParams pageParams, QueryCourseParamsDto queryCourseParams) {

        //1.分页查询 、条件模糊查询 、课程名词、审核状态、发布状态
        PageParams params = new PageParams();
        Page<CourseBase> courseBasePage = new Page<>(params.getPageNo(), params.getPageSize());

        LambdaQueryWrapper<CourseBase> wrapper = new LambdaQueryWrapper<>();

        wrapper.like(StringUtils.hasText(queryCourseParams.getCourseName()), CourseBase::getCompanyName,
                queryCourseParams.getCourseName());

        wrapper.eq(StringUtils.hasText(queryCourseParams.getAuditStatus()), CourseBase::getAuditStatus,
                queryCourseParams.getAuditStatus());

        wrapper.eq(StringUtils.hasText(queryCourseParams.getPublishStatus()), CourseBase::getStatus,
                queryCourseParams.getPublishStatus());

        page(courseBasePage,wrapper);

        return new PageResult<>(courseBasePage.getRecords(), courseBasePage.getTotal(), params.getPageNo(), params.getPageSize());
    }
}
